<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h4>区间质数判断器</h4>
    <input type="text" id="num1" placeholder="请输入一个数" />
    <input type="text" id="num2" placeholder="请输入一个数" />
    <button id="btn">判断</button>
    <script>
      function torf(a, b) {
        for (var i = a; i <= b; ++i) calc(i);
      }
      function calc(a) {
        var flag = true;
        for (var j = 2; j <= a / 2; ++j) {
          if (a % j == 0) {
            flag = false;
            break;
          }
        }
        if (flag == true) {
          document.write(a + "<br>");
        }
      }
      var num_1 = document.getElementById("num1");
      var num_2 = document.getElementById("num2");
      btn.onclick = function () {
        var a = parseInt(num_1.value);
        var b = parseInt(num_2.value);

        torf(a, b);
      };
    </script>
  </body>
</html>
